package com.auxgroup.hr.front.service.hireperson.impl;

import java.sql.Timestamp;
import java.util.List;

import com.auxgroup.hr.front.service.hireperson.HireZcglService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import com.auxgroup.hr.front.commons.utils.ObjectFieldUtils;
import com.auxgroup.hr.front.dao.domain.PsCHirePrimaryClass;
import com.auxgroup.hr.front.dao.domain.PsCHireZcglT;
import com.auxgroup.hr.front.dao.repository.PsCHireZcglTRepository;

/** 
 * @author lvliuhao
 * @version 创建时间：180523 
 * 入职人员职称经历service
 */
@Service("hireZcglService")
public class HireZcglServiceImpl implements HireZcglService {
	private static final Logger logger = LoggerFactory.getLogger(HireEducatServiceImpl.class);
	
	@Autowired
	private PsCHireZcglTRepository PsCHireZcglTRepository;


	@Override
	public PsCHireZcglT getHireZcgl(PsCHirePrimaryClass hirePrimary) {
		return PsCHireZcglTRepository.findOne(hirePrimary);
	}


	@Override
	public PsCHireZcglT save(PsCHireZcglT HireZcgl) {
		if(HireZcgl.getcSeqno()==null){
			HireZcgl.setHrsRowAddOprid(HireZcgl.getRsHireId());
			HireZcgl.setHrsRowAddDttm(new Timestamp(System.currentTimeMillis()));
		}
		HireZcgl.setHrsRowUpdOprid(HireZcgl.getRsHireId());
		HireZcgl.setHrsRowUpdDttm(new Timestamp(System.currentTimeMillis()));
		ObjectFieldUtils.handleNullValue(HireZcgl);
		return PsCHireZcglTRepository.save(HireZcgl);
	}


	@Override
	public Boolean delete(PsCHirePrimaryClass hirePrimary) {
		try {
			PsCHireZcglTRepository.delete(hirePrimary);
		} catch (Exception e) {
			logger.error("delete HireZcgl error: hirePrimary={}",hirePrimary,e);
			return false;
		}
		return true;
	}
	
	
	@Override
	public List<PsCHireZcglT> getAll(String rsHireId) {
		PsCHireZcglT HireZcgl = new PsCHireZcglT();
		HireZcgl.setRsHireId(rsHireId);
		return PsCHireZcglTRepository.findAll(Example.of(HireZcgl),new Sort(Sort.Direction.DESC,"cDate"));
	}


	
	
	
}
